from typing import List
from pydantic import Field, BaseModel
from package.fastapi.schema import BatchId, Page


class Login(BaseModel):
    name: str = Field(..., title='')
    password: str = Field(..., title='')


class ApiKeyEdit(BaseModel):
    expired_at: int = Field(..., title='过期时间')


class ApiKeyIn(ApiKeyEdit):
    name: str = Field(..., title='')


class ApiKeyOut(ApiKeyIn):
    id: str = Field(..., title='')

    class Config:
        orm_mode = True


class OidcEdit(BaseModel):
    client_secret: str = Field(..., title='客户端ID')
    authorization_url: str = Field(..., title='认证地址')
    token_url: str = Field('', title='token地址')
    verify_url: str = Field('', title='验证地址')
    redirect_url: str = Field('', title='日志平台回调地址', example='https://192.168.101.x')
    cert: str = Field('', title='证书')

    role_id: str = Field(None, title='角色 对应平台的角色')
    userid_field: str = Field(None, title='用户ID字段')
    username_field: str = Field(None, title='用户名字段')


class OidcIn(OidcEdit):
    state: str = Field(..., title='OIDC名称')
    client_id: str = Field(..., title='客户端ID')


class OidcOut(OidcIn):
    id: str = Field(..., title='OIDC id')

    class Config:
        orm_mode = True


class PageOidc(Page):
    """获取页码条目"""
    data: List[OidcOut] = Field(..., title='')